/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.service.plugins  
 */
package com.apache.uct.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.uct.common.entity.Org;
import com.apache.uct.manager.OrgManager;

/**
 * description:  按属性获取机构信息
 * @author dwusoft 创建时间：2015-3-30  
 * @Copyright(c)2014:北京--软件技术有限公司
 */
public class OrgEntityPlugin implements PluginConnector {

	private OrgManager orgManager;

	/**
	 * TODO 按属性获取机构信息(ID,OrgEname,fullEname).  <br>
	 * 参数说明:<br>
	 * propertyName:属性名称<br>
	 * propertyValue:属性值
	 */
	public Object execute(ParamsVo vo) throws Exception {
		String propertyName = String.valueOf(vo.getParams("propertyName"));
		String propertyValue = String.valueOf(vo.getParams("propertyValue"));
		ResultEntity result = new ResultEntity();
		try {
			result.setResult("true");
			if ("orgId".equals(propertyName) || "orgEname".equals(propertyName) || "fullEname".equals(propertyName)) {
				ParamsVo pvo = new ParamsVo();
				pvo.setParams("propertyName", propertyName);
				pvo.setParams("propertyValue", propertyValue);
				pvo.setKey("ByOrgProperty");
				Org org = (Org) orgManager.execute(pvo);
				result.setEntity(org);
				result.setMessage("机构查询成功！");
			} else {
				result.setMessage("不支持属性" + propertyName + "的查询！");
			}
		} catch (Exception e) {
			result.setResult("false");
			result.setMessage("机构查询失败！");
		}
		return result;
	}

	public void setOrgManager(OrgManager orgManager) {
		this.orgManager = orgManager;
	}

}
